package at.fhh.se.tjr.client.model;

import javax.swing.JTextArea;

import at.fhh.se.tjr.client.controller.Controller;

public class MoteWrapper {

	// clearTable "addTableId"
	
	private final long id;

	private final short max_table_size = 10;

	private long[] checkTrafficJamTable = new long[max_table_size];
	
	private long distance;
	
	public MoteWrapper(long id){
		this.id = id;
	}

	public void clearTable(Long muh){
		for (int i = 0; i < checkTrafficJamTable.length; i++) {
			checkTrafficJamTable[i] = 0;
		}
		logActivity("cleared table");
	}
	
	public void addTableId(Long id){
		for (int i = 0; i < checkTrafficJamTable.length; i++) {
			if (checkTrafficJamTable[i] != 0){
				checkTrafficJamTable[i] = id;
				i = checkTrafficJamTable.length;
			}
		}
		logActivity("added ID to table " + id);
		Controller.getInstance().registerID(id);
//		Controller.getInstance().getMainWindow().getWrapperPanel().addID(id);
	}

	public void sendTrafficJamAheadMessage(){
		logActivity("sent Message TrafficJamAhead");
	}
	
	public void distanceChecked(Long distance){
		this.distance = distance;
		logActivity("changed distance to " + distance); 
		Controller.getInstance().changeDistance(distance);
	}
	
	JTextArea area = Controller.getInstance().getMainWindow().getText();
	public void logActivity(String msg){
		String old = area.getText();
		String newText = "***** " + getId() + ": " + msg + " *****";
		area.setText(newText + "\n" + old);
	}
	
	public long getId() {
		return id;
	}

	public long[] getCheckTrafficJamTable() {
		return checkTrafficJamTable;
	}

	public long getDistance() {
		return distance;
	}
	
	
}
